home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 January / EnigmA AMIGA RUN 33 (1999)(G.R. Edizioni)(IT)[!][issue 1999-01].iso / earcd / faq / computer-lang / ada / programming / part4.z / part4
Text File  |  1999-01-01  |  38KB  |  896 lines

  1. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!newsfeed.internetmci.com!howland.reston.ans.net!surfnet.nl!swsbe6.switch.ch!swidir.switch.ch!epflnews!dinews.epfl.ch!Magnus.Kempe
  2. From: Magnus.Kempe@di.epfl.ch (Magnus Kempe)
  3. Newsgroups: comp.lang.ada,comp.answers,news.answers
  4. Subject: Ada FAQ: Programming with Ada (part 4 of 4)
  5. Followup-To: poster
  6. Date: 30 May 1996 17:09:48 GMT
  7. Organization: None
  8. Lines: 871
  9. Sender: magnus@lglsun4.epfl.ch (Magnus Kempe)
  10. Approved: news-answers-request@MIT.EDU
  11. Distribution: world
  12. Message-ID: <4okkos$idt@disunms.epfl.ch>
  13. Reply-To: Magnus.Kempe@di.epfl.ch (Magnus Kempe)
  14. NNTP-Posting-Host: lglsun4.epfl.ch
  15. Mime-Version: 1.0
  16. Content-Type: text/plain; charset=iso-8859-1
  17. Content-Transfer-Encoding: 8bit
  18. Summary: Ada Programmer's Frequently Asked Questions (and answers),
  19.            part 4 of 4.
  20.          Please read before posting.
  21. Keywords: advanced language, artificial languages, computer software,
  22.           data processing, programming languages, Ada
  23. Xref: senator-bedfellow.mit.edu comp.lang.ada:45676 comp.answers:18999 news.answers:73085
  24.  
  25. Archive-name: computer-lang/Ada/programming/part4
  26. Comp-lang-ada-archive-name: programming/part4
  27. Posting-Frequency: monthly
  28. Last-modified: 22 May 1996
  29. Last-posted: 23 April 1996
  30.  
  31.                                Ada Programmer's
  32.                        Frequently Asked Questions (FAQ)
  33.  
  34.    IMPORTANT NOTE: No FAQ can substitute for real teaching and
  35.    documentation. There is an annotated list of Ada books in the
  36.    companion comp.lang.ada FAQ.
  37.  
  38.     Recent changes to this FAQ are listed in the first section after the table
  39.     of contents. This document is under explicit copyright.
  40.  
  41. This is part 4 of a 4-part posting; part 1 contains the table of contents.
  42. Part 2 begins with question 5.
  43. Part 3 begins with question 6.
  44. Parts 1, 2, and 3 should be the previous postings in this thread.
  45.  
  46.  
  47. 9: Ada and Other Programming Languages
  48.  
  49.  
  50. 9.1: Where can I find programs that will translate from [some language] to
  51. Ada?
  52.  
  53.    It is generally advisable to simply interface from Ada to the
  54.    existing code segments that (should) already work. Note that Ada (95)
  55.    now has an annex devoted to specifying how to interface with code
  56.    written in other programming languages (C, Fotran, and Cobol), and
  57.    there are already interfaces to C++ too.
  58.  
  59.    Another option is to redesign the code, taking of course advantage of
  60.    one's knowledge of the current system. For instance, Job Honig
  61.    reported that he did this twice, once for Coco, a parser generator for
  62.    LALR left attributed grammars, and once for Flex, the well known
  63.    scanner generator. Both attempts revealed errors in the original
  64.    software; they were uncovered by designing the new system using the
  65.    higher abstraction level allowed by Ada...
  66.  
  67.    So there is support for the requirements analysis (transition to Ada),
  68.    but it is not obvious that the proposed implementation (using a source
  69.    code translator) is a good solution.
  70.  
  71.    Still, you may have compelling reasons to translate your existing
  72.    source to Ada. In that case, here is a list of available translators:
  73.  
  74.      * Pascal to Ada:
  75.  
  76.        R.R. Software's Pastran program (Pascal to Ada Translator).
  77.  
  78.        To see the differences in programming style, see "Ada for
  79.        Experienced Programmers", by A. Nico Habermann and Dewayne E.
  80.        Perry (Addison-Wesley Pub. Co., Reading, Mass., 1983). Covers Ada
  81.        and Pascal.
  82.  
  83.      * Fortran to Ada: ???
  84.  
  85.      * COBOL to Ada: ???
  86.  
  87.      * C++ to Ada: ???
  88.  
  89.      * C to Ada: ???
  90.  
  91.      * Modula-2 to Ada:
  92.  
  93.        (from Wayne R. Lawton)
  94.        The Idaho National Engineering Laboratory (INEL), a Dept of Energy
  95.        Lab has a basic capability for Modula-2 to Ada-83. The tool is
  96.        "research grade" quality, but may provide a starting point for
  97.        what you need. This is the same group of people who brought you
  98.        AdaSAGE. Give them a ring at (208) 526-0656. This is an answer
  99.        desk hotline in the section that wrote the tool.
  100.  
  101.        If you are looking for commercial quality, I wish you the best of
  102.        luck. If you just need something to perform 80% of the grunt code
  103.        translation, I think this might meet your needs. I know of two
  104.        systems comprising about 250,000 lines of code that were
  105.        originally developed in Modula-2 then translated and cleaned up in
  106.        Ada 83 after Alsys 1.0 for the PC came out back around 1987.
  107.  
  108.      * Visual Basic to Ada: NOT! :-)
  109.  
  110.  
  111. 9.2: How can I convert Ada 83 sources to Ada 9X?
  112.  
  113.    First you should read the following document, which will provide you
  114.    with much useful information: "Changes to Ada -- 1987 to 1995", file
  115.    ch83.{ps,doc}, in directory
  116.    ftp://sw-eng.falls-church.va.us/public/AdaIC/standards/95lrm_rat/v6.0
  117.  
  118.  
  119.    If you're using GNAT, the tool you are probably looking for is
  120.    "gnatchop". In csh you could use something like this to quickly
  121.    process existing files:
  122.  
  123.      cd dest_dir                    # The destination directory
  124.      foreach f ( ../src_dir/*.a )   # ../src_dir is the source directory
  125.        gnatchop $f
  126.      end
  127.  
  128.    gnatchop will show you what sources are causing problems.
  129.  
  130.  
  131. 9.3: I hear that Ada is slower than Fortran or C, is that true?
  132.  
  133.    First, note that you are comparing compilers, not languages. There is
  134.    no such thing as "fast" Ada code any more than there is "fast" C++ or
  135.    Fortran code. Now, when comparing execution speeds on similar
  136.    platforms, you must keep in mind the optimization levels, OS tuning,
  137.    etc. while making the comparisons. The bottom line is that
  138.    benchmarking, especially between two different languages, requires
  139.    _very_ careful measurement. In general, such results should be viewed
  140.    with caution.
  141.  
  142.    (A message from Bevin Brett of DEC)
  143.  
  144.    I have been asked to comment on the relative performance of algorithms
  145.    coded in Ada and in Fortran.
  146.  
  147.    This question has come up repeatedly over the years, and deserves a
  148.    complete answer, rather than a simplistic one.
  149.  
  150.    There are many factors which influence the size and execution speed of
  151.    the running program, and they all play together to get a full answer.
  152.    I shall then discuss an exact Ada v. Fortran comparison that Digital
  153.    was involved in.
  154.  
  155.    First, a position statement: The variation between Ada and Fortran is
  156.    less than the variation within the language caused by the exact
  157.    implementation details. A person versed in the Ada issues should do as
  158.    well in Ada as a person versed in the Fortran issues will do in
  159.    Fortran. The size and execution speed of the result should be within a
  160.    few percent of each other.
  161.  
  162.    (a) Differences due to the compiler
  163.  
  164.    In the case of the DEC Ada and Fortran compilers, the optimizer and
  165.        code generator are the same. Never-the-less, the exact inputs into
  166.        the optimizer and code generator may differ slightly when the same
  167.        algorithm is compiled by the Ada and Fortran compilers, and this
  168.        can result in major differences in the generated code. In these
  169.        cases the compiler front ends can usually be modified to correct
  170.        the slower one.
  171.  
  172.        We have not observed any major differences in generated code
  173.        quality between the DEC Ada and DEC Fortran compilers caused by
  174.        such issues.
  175.  
  176.  
  177.    (b) Differences due to the language
  178.  
  179.    It is very important that the same algorithm be written in the two
  180.        languages. The biggest differences we have observed are
  181.          1. Having the wrong dimension varying fastest, since it is
  182.             desireable to have the first dimension changing fastest in
  183.             Fortran, and the last dimension in Ada. Thus when an
  184.             algorithm is transliterated, the array indexes must be
  185.             reversed.
  186.  
  187.          2. Using compile-time-known bounds for arrays in Fortran, and
  188.             using unconstrained arrays in the Ada code. Knowing the exact
  189.             values of the dimensions at compile-time results in much
  190.             better code.
  191.  
  192.          3. Not suppressing all the runtime checks in Ada. The Fortran
  193.             compiler assumes all array bounds are in range, and all
  194.             arithmetic operations do not overflow. You must use a pragma
  195.             Suppress to tell this to the Ada compiler as well.
  196.  
  197.          4. Don't use arrays of Ada Booleans to match arrays of Fortran
  198.             Integers, because accessing bytes on a RISC system might be
  199.             much worse than accessing fullwords.
  200.  
  201.  
  202.    (c) Differences due to the bindings
  203.  
  204.    The biggest bindings differences are related to Fortran's built-in
  205.        support for complex types, and for various math routines such as
  206.        SQRT and SIN, compared with Ada code that often uses hand-coded or
  207.        ISO standardised versions of these functions with different
  208.        requirements than are imposed on the Fortran versions.
  209.  
  210.        DEC Ada has built-in support for complex types, and also has
  211.        bindings directly to the same primitives that Fortran uses for its
  212.        math routines and so gets the same performance as Fortran does.
  213.  
  214.  
  215.    (d) Differences due to the author
  216.  
  217.    The use of good Ada and Fortran style can also effect the generated
  218.        code. Provided the author writes in good Ada style, and follows
  219.        the above guidelines, the generated code should do as well as
  220.        Fortran.
  221.  
  222.  
  223.     The Ada Performance Benchmark
  224.  
  225.    A DEC Ada customer had a Fortran benchmark that had been translated
  226.    into Ada without awareness of the above issues, and was running
  227.    substantially slower with DEC Ada than the original was with DEC
  228.    Fortran.
  229.  
  230.    Bevin Brett, a DEC Ada team member, developed the above guidelines in
  231.    the process of retranslating the code into Ada.
  232.  
  233.    Portions of this translation are shown here (a) as an illustration of
  234.    the application of the above rules, and (b) as an illustration of the
  235.    kind of operations that were present in the benchmark.
  236.  
  237.    The whole benchmark has not been provided to avoid possible issues of
  238.    ownership.
  239.  
  240.    The resulting Ada benchmark components each ran within a few percent
  241.    of their Fortran counterparts. The Ada code is available by FTP, in
  242.    file ftp://lglftp.epfl.ch/pub/Ada/FAQ/ada-vs-fortran.ada
  243.  
  244.  
  245. 9.4: Isn't Ada less "elegant" than Eiffel?
  246.  
  247.    While it is true that programming-language support for "assertions"
  248.    is an important contribution of Eiffel to software construction, this
  249.    is not an issue of "elegance", and there are many other important
  250.    factors to consider.
  251.  
  252.    Note also that preconditions and postconditions can be fairly easily
  253.    and efficiently included in Ada code. Invariants seem difficult to
  254.    emulate directly in Ada. If you're really interested in the formal use
  255.    of assertions with Ada, maybe Anna is a solution for you.
  256.  
  257.    (Tucker Taft comments)
  258.  
  259.    I guess one thing that bothers me a little is that people are quick to
  260.    say that Eiffel is "elegant" without really looking at it. I fear that
  261.    such statements will become self-fulfilling prophecies, with those
  262.    programmers interested in elegance migrating over to Eiffel rather
  263.    than sticking with Ada.
  264.  
  265.    In particular, although I like the assertion stuff in Eiffel, I think
  266.    the language has a number of "inelegant" aspects. For example:
  267.  
  268.     1. exception handlers only at the top level of a routine, with the
  269.        only way to "handle" an exception being by retrying the whole
  270.        routine.
  271.  
  272.     2. No way to return from a routine in the middle. This makes it a
  273.        pain in the neck to search through a list for something in a loop,
  274.        and then return immediately when you find what you want. (I have
  275.        never found the addition of extra boolean control variable a help
  276.        to the understanding of an algorithm.)
  277.  
  278.     3. Namespace control handled by a separate sublanguage, and no real
  279.        higher level concept of "module" or "subsystem."
  280.  
  281.     4. An obscure notation like "!!" being used for an important and
  282.        frequent operation (construction).
  283.  
  284.     5. No way to conveniently "use" another abstraction without
  285.        inheriting from it.
  286.  
  287.     6. No strong distinctions between integer types used for array
  288.        indexing.
  289.  
  290.     7. Using the same operator ":=" for both (aliasing) pointer
  291.        assignment, and for value assignment, depending on whether the
  292.        type is "expanded." (Simula's solution was far preferable, IMHO).
  293.  
  294.     And most critically:
  295.  
  296.  
  297.     8. No separate interface for an abstraction. You can view a interface
  298.        by running a tool, but this misses completely the importance of
  299.        having a physical module that represents the interface, and acts
  300.        as a contract between the specifier or user of an abstraction and
  301.        its implementor. In Eiffel, one might not even be truly aware when
  302.        one is changing the interface to an abstraction, because there is
  303.        no particular physical separation between interface and
  304.        implementation.
  305.  
  306.  
  307.    I consider many of the above problems quite serious, with some of them
  308.    being real throwbacks to the old style of programming languages where
  309.    there were no well defined interfaces or modules.
  310.  
  311.    Hence, I cringe a bit when people say that Eiffel is the "most
  312.    elegant" OOP and that they would use it if only it were practical to
  313.    do so. In many ways, I think Ada is much better human-engineered than
  314.    Eiffel, with important things like range constraints built into the
  315.    language in a way that makes them convenient to use. Although general
  316.    assertions are nice, they don't give you the kind of line-by-line
  317.    consistency checks that Ada can give you.
  318.  
  319.    To summarize --
  320.    Although Eiffel certainly has a number of nice features, I don't
  321.    consider it ready for prime time as far as building and maintaining
  322.    large systems with large numbers of programmers. And from a human
  323.    engineering point of view, I think Ada is significantly better.
  324.  
  325.  
  326. 9.5: Are there any papers detailing the differences between Ada and C++?
  327.  
  328.    Below are two references. Bear in mind that it is difficult to make
  329.    such a comparison without exposing biases. However, the two papers
  330.    below are well worth reading.
  331.  
  332.    "A Comparison of the OO features of Ada9x and C++" in Springer Lecture
  333.    Notes in CS: "Ada Europe 93" pp.125-141 (short paper, good reading,
  334.    enlightens idioms)
  335.  
  336.    ftp ajpo.sei.cmu.edu in directory: /public/ada9x, document:
  337.    9x_cplus.hlp
  338.  
  339.  
  340. 9.6: I keep hearing that Ada is a "strongly typed language", but it seems
  341. different from what's meant in C++. Are they different?
  342.  
  343.    (Tucker Taft responds)
  344.  
  345.    I certainly agree that ANSI C and C++ are statically typed languages,
  346.    but I would debate the "strength" of their typing.
  347.  
  348.    Essentially any support for implicit conversion (implicit "casting,"
  349.    "promotion", "usual" arithmetic conversions, etc.) "weakens" a type
  350.    system (but also makes it "friendlier" in some ways).
  351.  
  352.    C allows implicit conversion between all integer types and all
  353.    enumeration types. C++ at least cuts off implicit conversion to
  354.    enumeration types, but retains implicit conversion among all integer
  355.    (and floating-point) types. Also, in both C and C++, typedefs for
  356.    pointer/array types are essentially "macros"; all pointer types with
  357.    the same target type are implicitly interconvertible.
  358.  
  359.    Finally C++ allows the user to define a number of their own implicit
  360.    conversion operators, which basically allows the user to "weaken" the
  361.    type system as they see fit.
  362.  
  363.    Of course, all of this implicit conversion serves a purpose, but it
  364.    does tend to move C/C++ toward the "weaker" end of the weak vs. strong
  365.    typing spectrum.
  366.  
  367.    Note that the "strong" distinctions between integer types helps
  368.    dramatically in catching (at compile-time) array indexing errors in
  369.    Ada programs, by making sure that if you have an array indexed by a
  370.    count of apples, you don't index into it with a count of oranges
  371.    (without an *explicit* conversion). The advantages of "strongly"
  372.    distinguishing enumeration types is even more obvious (and the
  373.    designers of C++ recognized this).
  374.  
  375.    The strong distinctions between access types (pointer types) in Ada
  376.    also has advantages, allowing access types to be represented as
  377.    offsets within their storage pool rather than as addresses, and giving
  378.    more high-level control over storage management.
  379.  
  380.    Strong typing can be carried too far, and some amount of implicit
  381.    conversion is essential to make OOP palatable. But note that in Ada
  382.    9X, even with OOP, we don't allow implicit conversions that truncate
  383.    the extension part of a record (this is a relatively common mistake in
  384.    C++ when passing parameters by value). Instead, in Ada 9X, the
  385.    language distinguishes between a specific type T and the class-wide
  386.    type T'Class, and allows implicit conversions to T'Class from T or any
  387.    of its derivatives, but not to the specific type T. Conversions to the
  388.    class-wide type never implicitly truncate the extension part.
  389.    Conversions to a specific type can truncate, and hence must be
  390.    explicit.
  391.  
  392.    Note also that in Ada there are three distinct kinds of conversions,
  393.    implicit ones, explicit ones, and unchecked ones. Only the unchecked
  394.    ones are potentially unsafe. The explicit ones are safe, with either
  395.    compile-time or run-time checks to ensure that. In C there are only
  396.    implicit and explicit/unchecked conversions. C++ has recently added a
  397.    checked, explicit "dynamic" cast, but still it will be common to use
  398.    "normal" explicit casts for both checked and unchecked conversions,
  399.    thereby making it more difficult to identify places where the type
  400.    system might be compromised.
  401.  
  402.    Hence, the bottom line is that the type checking is (objectively)
  403.    "stronger" in Ada than C/C++, though that doesn't necessarily mean
  404.    "better" -- whether one is "better" for a particular style of
  405.    programming than the other is a "religious" issue IMHO. I know my
  406.    religion currently favors the stronger checking of Ada in most cases
  407.    [except perhaps for multiply/divide, where I personally believe the
  408.    checking should either be weaker, or directly support the concept of
  409.    "units"/"dimensions"].
  410.  
  411.  
  412. 9.7: I'm told Ada does all sorts of static type checking, but can't you get
  413. the same effect using a tool like "lint" with C?
  414.  
  415.    No, here are a few reasons why (this list is by no means complete):
  416.  
  417.    (Submitted by Norm Cohen)
  418.      * Running both Lint and a C compiler requires the program text to be
  419.        parsed and semantically analyzed twice. The results of an Ada
  420.        compiler's parse and semantic analysis are used directly in
  421.        performing consistency checks.
  422.  
  423.      * The rules of Ada provide the opportunity for stronger consistency
  424.        checks than are possible with C. For example, an Ada programmer
  425.        can declare distinct integer types to represent distinct
  426.        abstractions. An Ada compiler will catch an inadvertent
  427.        intermixing of these two types, but there is no way a
  428.        corresponding distinction can be made in C, so there is no way for
  429.        Lint to perform a corresponding check. Similarly, in C, a pointer
  430.        to an object of type T is indistinguishable from an array of
  431.        objects of type T.
  432.  
  433.      * The rules of the Ada language ensure that the program text
  434.        provides information allowing PRECISE consistency checks. For
  435.        example, the expression in an Ada case statement can be written to
  436.        have a static subtype, allowing the compiler to ascertain that all
  437.        possible values have been covered without resorting to a default
  438.        (when others) arm.
  439.  
  440.      * With lack of precise information, Lint has no choice but to be
  441.        overly pessimistic or, with different settings for a complicated
  442.        set of options, overly optimistic. When it is overly pessimistic,
  443.        the user sees too many "false alarms" and may end up ignoring
  444.        valid warnings. When it is overly optimistic, Lint overlooks
  445.        certain errors.
  446.  
  447.      * It is impossible to forget to run consistency checks when using an
  448.        Ada compiler. (Of course a C programming environment could be set
  449.        up so that the C compiler could only be invoked from a script that
  450.        also invokes Lint.)
  451.  
  452.      * A compilation that fails Ada consistency checks is rejected. A
  453.        compilation that fails Lint consistency checks may still be
  454.        compiled, and its object file used (intentionally or accidently)
  455.        in building the system. (One cannot automate the rejection of
  456.        programs that fail Lint unless one is certain that there will
  457.        never be any false warnings.)
  458.  
  459.      * Ada enforces consistency among separately compiled units.
  460.  
  461.  
  462.    Of course even stronger arguments can be made about Ada's RUN-TIME
  463.    checks (which can be used with little additional overhead because the
  464.    information contained in an Ada program and the knowledge that the
  465.    program has passed compile-time consistency checks make it possible to
  466.    optimize away the majority of the checks). These checks, which are
  467.    absent in C, tend to smoke out errors early by detecting internal
  468.    inconsistencies that might not otherwise be detected during testing.
  469.    This reduces the likelihood of fielding a system that appears to work
  470.    well during testing but fails in operational use.
  471.  
  472.  
  473. 9.8: Does Ada have something like the Standard Template Library (STL) in C++,
  474. or components like you find in Smalltalk environments?
  475.  
  476.    Yes, in various ways.
  477.  
  478.    Few components are part of the ISO standard. Ada 95 has an expanded
  479.    set of predefined library units, covering e.g. strings of varying- or
  480.    dynamic-length, elementary numerical functions, random number
  481.    generators, complex numbers, and more; in addition, the Special Needs
  482.    Annexes standardize many advanced services which have commonly been
  483.    provided by separate components in the past.
  484.  
  485.    A lot of free Ada software components are available from anonymous FTP
  486.    sites. There is also an upcoming release of the Booch Components for
  487.    Ada 95 under the GNU Library General Public License (LGPL); this will
  488.    give you the ability to freely include the library components in your
  489.    application without any cost or obligation. (Contact dweller@dfw.net
  490.    for more details.)
  491.  
  492.     What about STL and the Smalltalk library?
  493.  
  494.    The C++ STL doesn't contain much. Really. Breaking its source code
  495.    down, it contains less than 3000 semicolons (~7000 total lines). The
  496.    entire library exists in C++ header files as inlineable code
  497.    (supposedly within a few percent of the efficiency of hand-optimized
  498.    code).
  499.  
  500.    STL class hierarchy
  501.  
  502.      bool, heap     -- of course Ada does not need a bool class!
  503.       \ function, pair, stack
  504.          \ iterator, tempbuf, projection
  505.             \ algobase
  506.                \ algorithms, bitvector, deque, list, tree, vector
  507.                   \ map, multimap, set, multiset
  508.  
  509.  
  510.    The main author of the library, Alexander Stepanov, created the Ada
  511.    Generic Library in the 1980's -- and later borrowed from this to
  512.    create STL. (There is an interview with Stepanov in the March 1995
  513.    issue of Dr. Dobb's Journal -- in the C Programming column beginning
  514.    on page 115. Stepanov explains that these components were first done
  515.    in Ada.)
  516.  
  517.    The Smalltalk library is quite eclectic. It covers everything from
  518.    Boolean to bitmaps, dictionaries and other collections. Parts of it
  519.    have direct equivalents in Ada 95, parts are already available in
  520.    components from anonymous FTP sites and/or will be in the Booch Ada 95
  521.    components, and other parts are available from commercial Ada
  522.    component suppliers.
  523.  
  524.  
  525. 9.9: Where can I find the equivalent of "printf" in Ada?
  526.  
  527.    While the standard package Text_IO provides many features, the
  528.    request for a printf-like function is not unusual.
  529.  
  530.    (solution based on a suggestion by Tucker Taft)
  531.  
  532.    It is possible to produce a printf-like capability by overloading the
  533.    "&" operator to take an object of type Format and an object of some
  534.    type and return the Format, properly advanced, after having performed
  535.    the appropriate output. The remaining format can be converted back to
  536.    a string--e.g. to examine what is left at the end of the format
  537.    string-- or simply printed to display whatever remains at the end. For
  538.    example:
  539.  
  540.      with Text_IO;
  541.      package Formatted_Output is
  542.        type Format is
  543.          limited private;
  544.  
  545.        function Fmt (Str : String)
  546.          return Format;
  547.  
  548.        function "&" (Left : Format; Right : Integer)
  549.          return Format;
  550.        function "&" (Left : Format; Right : Float)
  551.          return Format;
  552.        function "&" (Left : Format; Right : String)
  553.          return Format;
  554.        ... -- other overloadings of "&"
  555.  
  556.        procedure Print (Fmt : Format);
  557.  
  558.        function To_String (Fmt : Format)
  559.          return String;
  560.  
  561.      private
  562.        ...
  563.      end Formatted_Output;
  564.  
  565.      with Formatted_Output; use Formatted_Output;
  566.      procedure Test is
  567.        X, Y : Float;
  568.      begin
  569.        Print (Fmt("%d * %d = %d\n") & X & Y & X*Y);
  570.      end Test;
  571.  
  572.    The private part and body of Formatted_Output are left as an exercise
  573.    for the reader ;-).
  574.  
  575.    A "File : File_Type" parameter could be added to an overloading of Fmt
  576.    if desired (to create something analogous to fprintf).
  577.  
  578.    This capability is analogous to that provided by the "<<" stream
  579.    operator of C++.
  580.  
  581.      _________________________________________________________________
  582.  
  583.  
  584. 10: Interfacing with Ada
  585.  
  586.  
  587. 10.1: I am writing software that used the Distributed Interactive Simulation
  588. (DIS) interface, does an interface exist in Ada?
  589.  
  590.    Yes. DIS is a standard for communications between simulators using an
  591.    Internet Protocol network (IP). DIS provides a unified virtual
  592.    environment for multiple simulator users on a network. It is used
  593.    mostly in the DoD simulations business, but it is applicable to ANY
  594.    simulation. It is an industry initiative involving military training
  595.    and procurement organisations, simulator vendors and universities
  596.    mostly in the US, but the technology is unclassified.
  597.  
  598.    The US Army is funding quite a bit of DIS research and development.
  599.    The Institute of Simulation and Training, URL
  600.    http://www.tiig.ist.ucf.edu/ is a center at the University of Central
  601.    Florida (UCF) which serves as the support contractor for the UCF IST,
  602.    as are BBS's for the DIS working groups who are attempting to push
  603.    those standards forward. The BBS contains an Ada binding for DIS.
  604.  
  605.    Note that the above provides a thin binding to C code. It may be
  606.    worthwhile to take the time to make high-level DIS bindings. Ted
  607.    Dennison, dennison@escmail.orl.mmc.com reports having done it (while
  608.    working for what is now Lockheed Martin Simulation Systems) in over 2
  609.    man-months using an experienced Ada engineer, and that it was well
  610.    worth it. Many bugs were found in the C DIS code of the machine they
  611.    were networked with. "A strongly-typed interface is the network
  612.    programmer's best friend."
  613.  
  614.    At TRI-Ada'94 there was a demonstration by Coleman Research
  615.    Corporation (CRC); here's their short pitch: "CRC presents Ada
  616.    VR-Link, the first commercially available DIS NIV. It provides all of
  617.    the facilities necessary to jump start your DIS compliant simulation
  618.    development efforts. For more information call (205) 922-6000."
  619.  
  620.    Also, the AJPO sponsored an Ada Technology Insertion Program (ATIP)
  621.    relating to this: FY93 ATIP project 17, titled "Ada Distributed
  622.    Interactive Simulation (ADIS)". Available from directory
  623.    ftp://sw-eng.falls-church.va.us/public/AdaIC/source-code/bindings
  624.        /ADIS-bindings
  625.  
  626.    The Ada Distributed Interactive Simulation (ADIS) provides an Ada
  627.    interface to the IEEE 1278 Distributed Interactive Simulation (DIS)
  628.    protocols. The project was developed in Ada 83 (MIL-STD-1815), on
  629.    Silicon Graphics Indigo R4000 machines using Verdix Ada 6.2.1 under
  630.    the IRIX operating system, version 5.2. The Graphical User Interfaces
  631.    (GUIs) were developed for X Window version X11R5 using Motif 1.2.
  632.  
  633.    There are several sources of information available on DIS itself. The
  634.    IEEE version of the DIS standard is available through (and only
  635.    through) the IEEE (std IEEE 1278). Draft versions of the standard are
  636.    available from the Institute for Simulation and Training at the
  637.    University of Central Florida. They take orders at (407) 855-0881, and
  638.    questions (about ordering) at (407) 658-5054.
  639.  
  640.  
  641. 10.2: Is there any support for Common Object Request Broker Architecture
  642. (CORBA) for Ada 9X?
  643.  
  644.    OC Systems sells a CORBA Ada product; it is "Standard equipment" with
  645.    their PowerAda compiler. Rational, and OIS are also planning on
  646.    selling CORBA products for Ada.
  647.  
  648.    Objective Interface Systems, Inc. (OIS), MITRE, and DISA have been
  649.    working on a mapping from CORBA IDL to Ada 95 for about six months.
  650.    Bill Beckwith (Bill.Beckwith@ois.com) will send a recent copy of the
  651.    mapping document to any interested parties.
  652.  
  653.    Note that CORBA IDL to Ada 95 mapping specifies a mapping, not a
  654.    binding. This will put Ada 95 on equal footing with the C++ and
  655.    Smalltalk products. (except that, of course, the Ada mapping is
  656.    cleaner ;-).
  657.  
  658.      _________________________________________________________________
  659.  
  660. 11: Finding Additional Information
  661.  
  662. 11.1: Where can I find Ada books?
  663.  
  664.    Look at the companion comp.lang.ada FAQ or the HBAP WWW Server, URL
  665.    http://lglwww.epfl.ch/Ada/
  666.  
  667.    Michael Feldman maintains the "Annotated Sampling of Ada-Oriented
  668.    Textbooks"; if you don't have access to WWW, drop him a note at
  669.    mfeldman@seas.gwu.edu
  670.  
  671.  
  672. 11.2: Are there other Ada-related FAQs?
  673.  
  674.    Yes. They all appear in comp.lang.ada at regular intervals:
  675.    comp.lang.ada FAQ, public Ada library FAQ, and Ada WWW server FAQ. All
  676.    these are permanently available in hypertext format from the HBAP WWW
  677.    Server (see below) and in ASCII format from
  678.    ftp://lglftp.epfl.ch/Ada/FAQ
  679.  
  680.  
  681. 11.3: What is the "HBAP WWW Server"?
  682.  
  683.    The Home of the Brave Ada Programmers (HBAP) WWW Server is alive and
  684.    heavily used. It is a hypertext, multimedia information server for the
  685.    Ada programming language.
  686.  
  687.    The URL of the HBAP WWW Server is
  688.  
  689.         http://lglwww.epfl.ch/Ada/
  690.  
  691.    [don't forget the trailing '/'.]
  692.  
  693.    The HBAP WWW Server provides Ada-related information and hypertext
  694.    access in areas including:
  695.      * Historical notes on Ada
  696.      * References
  697.      * Ada FAQs
  698.      * State of Ada 9X revision process
  699.      * Standards
  700.      * Bindings
  701.      * Tools and Components
  702.      * Intellectual Ammunition
  703.      * Introductory Material
  704.      * Resources
  705.      * CS Technical Reports
  706.      * FTP and WWW Sites--including mirror sites
  707.      * Calendar of Ada-related events
  708.      * Ada Today
  709.      * Frequently Asked Questions--with Answers (from comp.lang.ada)
  710.  
  711.  
  712.    For instance, you will find a list of schools using Ada in CS1 or CS2,
  713.    an article on commercial success stories, information about software
  714.    components, as well as hypertext versions of the Ada reference manual
  715.    (both 83 and draft 9X).
  716.  
  717.    The HBAP WWW Server keeps growing. All comments, ideas, and requests
  718.    for additions or corrections, are welcome (e-mail to
  719.    Magnus.Kempe@di.epfl.ch).
  720.  
  721.      _________________________________________________________________
  722.  
  723.  
  724. 12: Pretty-printing and Measuring Ada Source Code
  725.  
  726.  
  727. 12.1: Is there software that generates a pretty PostScript file from Ada
  728. source code?
  729.  
  730.    Pretty Ada code in PostScript means that e.g. reserved words are in
  731.    bold and comments are in italics. This is a separate issue from
  732.    re-formatting and automatic indenting.
  733.  
  734.    If you use the new Ada Mode for GNU Emacs (available from
  735.    ftp://cs.nyu.edu/pub/gnat), go and get the package ps-print.el from
  736.    any emacs archive (e.g. in directory
  737.    ftp://archive.cis.ohio-state.edu/pub/gnu/emacs/elisp-archive). With
  738.    this package you can print your code as you see it on the screen, say
  739.    with bold keywords and italic comments.
  740.  
  741.    Another possibility is to feed the source to "vgrind" (see below),
  742.    then pipe the result through "pscat" (to get PostScript) or "lpr -t"
  743.    (to print), e.g.:
  744.  
  745.      vgrind -d <vgrind_defs_file> -lada -o1- -t -w $* | lpr -t
  746.  
  747.  
  748. 12.2: I use vgrind to do "pretty printing" of my source. Is there a vgrind
  749. definition for Ada?
  750.  
  751.  
  752. # Ada!
  753. ada|Ada:\
  754.         :pb=(^\d?(procedure|function|package|package body))\d\p:\
  755.         :bb=if|case|begin|loop:be=end:\
  756.         :cb=--:ce=$:\
  757.         :sb=":se=":\
  758.         :lb=':le=':\
  759.         :id=_.:\
  760.         :oc:\
  761.         :kw=abort abs abstract accept access aliased all and array at\
  762.         begin body case constant declare delay delta digits do else\
  763.         elsif end entry exception exit for function generic goto if in is\
  764.         limited loop mod new not null of or others out package pragma\
  765.         private procedure protected raise range record rem renames requeue\
  766.         return reverse select separate subtype tagged task terminate then\
  767.         type until use when while with xor:
  768.  
  769.  
  770.    Note that the above has a problem with attributes, because the "lb"
  771.    and "le" terms make two-attributes-20-lines-apart look like one
  772.    "string literal." Ada 95 keywords are recognized.
  773.  
  774.    Here is another definition, which "fixes" this problem (not perfect,
  775.    but probably better). Only Ada 83 keywords are recognized.
  776.  
  777.  # In order to get the ticks to work, we are assuming that there will be
  778.  # whitespace before a literal (like '"') and *not* when used for an
  779.  # attribute (like 'Length).
  780.  # For sb/se, we are ALSO assuming that literals have whitespace before/after.
  781. Ada|ada:\
  782.         :pb=^\d?(procedure|function|package|package\dbody)\d\p:\
  783.         :bb=begin:be=end:\
  784.         :cb=--:ce=$:\
  785.         :sb=( |\t|\()":se="( |\t|;|,|\)):\
  786.         :lb=(>| |\t)':le='(\)| |\t|;):\
  787.         :tl:\
  788.         :oc:\
  789.         :kw=abort abs accept access all and array at begin body case constant\
  790.         declare delay delta digits do else elsif end entry exception exit for\
  791.         function generic goto if in is limited loop mod new not null of or\
  792.         others out package pragma private procedure raise range record rem\
  793.         renames return reverse select separate subtype task terminate then\
  794.         type use when while with xor:
  795.  
  796.  
  797. 12.3: How about a source code reformatter?
  798.  
  799.    If you can run a Perl script (Perl is freely available for almost
  800.    every OS in the world), you can use the program aimap, written by Tom
  801.    Quiggle of SGI. aimap is not really a pretty printer, since it only
  802.    changes the case of identifiers and reserved words (according to the
  803.    options set). It can be found at
  804.    http://reality.sgi.com/employees/quiggle_engr/aimap
  805.  
  806.  
  807. 12.4: How can I count source lines of code (SLOC)?
  808.  
  809.    Under Unix and many operating systems (apparently even MS-DOS), the
  810.    following works well:
  811.  
  812.      wc -l file_name
  813.  
  814.  
  815.    If you only want to count "statement lines" (lines with semicolons),
  816.    use
  817.  
  818.      sed 's/--.*$//' file_name | grep ';' | wc -l
  819.  
  820.  
  821.    Some versions of grep have a '-c' option to print a count of the
  822.    matching lines, but this may not be universal. You can fold the
  823.    grepping into the sed command but that's not as readable:
  824.  
  825.      sed -n -e 's/--.*$//' -e '/;/p' file_name | wc -l
  826.  
  827.  
  828.    Please note that measuring SLOC should be used to indicate an
  829.    approximate relationship to the size of other projects, and as such,
  830.    provided that there is some uniformity in the form and number of
  831.    comments, it does not matter whether comments are counted or not. It
  832.    has often been observed that there is a very high correlation between
  833.    measurements of SLOC, semicolons, and Halstead bits (there is probably
  834.    also a high enough correlation with the number of characters).
  835.  
  836.    With VMS, try the following, which will print out the number of lines
  837.    ("records") and characters (use ";" instead of "~~~~~" to count lines
  838.    with semicolons; note that "records" will match even in comments):
  839.  
  840.      $ search/stat file_name.ada "~~~~~"
  841.  
  842.  
  843. 12.5: Can I measure other things?
  844.  
  845.    There is ASAP, the Ada Static Analyzer Program, written in Ada and
  846.    set up to compile under Dec Ada on a Vax running VMS. Gives SLOC,
  847.    McCabe's, and more. It is available via anonymous ftp in directory
  848.    ftp://ftp.sei.cmu.edu/pub/dd
  849.  
  850.  
  851.      _________________________________________________________________
  852.  
  853. 13: Credits
  854.  
  855.    The first draft was made by Dave Weller. The following persons have
  856.    contributed (directly or indirectly, intentionally or unintentionally,
  857.    through e.g. comp.lang.ada) to the information gathered in this FAQ:
  858.    Tucker Taft, Dave Weller, David Arno, Christine Ausnit, Bill Beckwith,
  859.    Moti Ben-Ari, Chip Bennett, Bevin Brett, David Bulman,
  860.    G. Vincent Castellano, Norm Cohen, Marin David Condic, John Cosby,
  861.    Richard Crutchfield, Theodore E. Dennison, Robert Dewar, Bob Duff,
  862.    Robert Eachus, Rolf Ebert, Dave Emery, Mitch Gart, Victor Giddings,
  863.    Jeffrey L. Grover, Laurent Guerby, Richard G. Hash, Matthew Heaney,
  864.    Fergus Henderson, Niklas Holsti, Job Honig, Jean D. Ichbiah,
  865.    Nasser Kettani, Wayne R. Lawton, Robert Martin, Robb Nebbe,
  866.    Jonathan Parker, Isaac Pentinmaki, Bruce Petrick, Paul Pukite,
  867.    Richard Riehle, Keith Shillington, David Shochat, André Spiegel,
  868.    Keith Thompson, Joyce Tokar, Kevin Weise, David A. Wheeler,
  869.    Fraser Wilson, and the maintainer has simply :-) organized, polished,
  870.    or added some information for your satisfaction. The general HTML
  871.    structure of this FAQ was originally inspired by the (now differently
  872.    structured) WWW FAQ.
  873.  
  874.      _________________________________________________________________
  875.  
  876. 14: Copying this FAQ
  877.  
  878.    This FAQ is Copyright © 1994-1996 by Magnus Kempe. It may be freely
  879.    redistributed --as posted by the copyright holder in comp.lang.ada--
  880.    in other forums than Usenet News as long as it is completely
  881.    unmodified and that no attempt is made to restrict any recipient from
  882.    redistributing it on the same terms. It may not be sold or
  883.    incorporated into commercial documents without the explicit written
  884.    permission of the copyright holder.
  885.  
  886.    Permission is granted for this document to be made available under the
  887.    same conditions for file transfer from sites offering unrestricted
  888.    file transfer on the Internet and from Forums on e.g. Compuserve and
  889.    Bix.
  890.  
  891.    This document is provided as is, without any warranty.
  892.  
  893.      _________________________________________________________________
  894.  
  895.     Magnus Kempe -- Magnus.Kempe@di.epfl.ch
  896.